<?php
namespace app\manager\model;
use think\Validate;
/**
 * 基础消息模型
 */
class BaseMsgs extends \think\Model
{
	protected $table = 'base_msgs';
	protected $code = 'failed';
	protected $autoWriteTimestamp = 'timestamp';
	
	public function saveBaseMsgs($data){
		$re = $this->baseValidate($data);
		if( $re['code'] == $this->code ){
			return $re;
		}
		try {
			if(empty($data['id'])){
				self::create($data);
			}
		    self::update($data);
		} catch (\Exception $e) {
		    throw $e;
		}		
	}
	
	public function baseValidate($data){
	    $validate = new Validate(
	    	[
		    	'subscribe' => 'require',
		    	'default'	=> 'require',
			],
			[
		        'subscribe' => '关注回复不能为空',
		        'default'   => '默认回复不能为空',
		    ]
		);
		if(!$validate->check($data)){
			return ['code' => $this->code, 'msg' => $validate -> getError()];
		}
	}
}




?>